<template>
  <div>
    <h2>注册页面</h2>
    <table class="table" border="1">
      <tr>
      <td>用户名</td>
      <td>
        <input type="text" v-model="state.Uname">
      </td>
    </tr>
    <tr>
      <td>密码</td>
      <td>
        <input type="text" v-model="state.Upwd">
      </td>
    </tr>
    <tr>
      <td colspan="2"><input type="button" value="注册" @click="register"></td>
    </tr>
    </table>
    
  </div>
</template>

<script setup lang="ts">
import router from '@/router';
import axios from 'axios';
import {reactive,toRefs} from 'vue'
let data=reactive({
  state:{
    Uname:"",
    Upwd:""
  }
})
let {state}=toRefs(data)


function register()
{
  axios({
    url:"http://localhost:51322/api/User/PostUserRegister",
    method:"post",
    data:state.value
  })
  .then(res=>{
    console.log(res);
    if(res.data.data==-1)
  {
    alert("用户名已存在请更换");
    return;
  }
  else if(res.data.data>0)
  {
    alert("注册成功");
    router.push("/login")
  }
  else{

    alert("注册失败");
    return;
  }
  })
  .catch(err=>{
    console.log(err);
  })

}
</script>

<style scoped>

</style>